
import store from '../store';
import Vue from 'vue'
/** 权限指令**/
const hasBtn = Vue.directive('hasBtn', {
  inserted(el, binding) {
    // 获取按钮权限
    if (!Vue.prototype.$_hasBtn(binding.value)) {
      el.parentNode.removeChild(el);
    }
  }
});
// 权限检查方法
Vue.prototype.$_hasBtn = function(value) {
  let isExist = false;
  const buttons = store.getters['d2admin/account/buttons'];
  const btnPermissionsStr = []
  buttons.map(o => {
    btnPermissionsStr.push(o.enCode)
    return o
  })
  if (btnPermissionsStr === undefined || btnPermissionsStr == null) {
    return false;
  }
  if (btnPermissionsStr.indexOf(value) > -1) {
    isExist = true;
  }
  return isExist;
};
export { hasBtn }